import { Notifier } from "../observer/Notifier";
import { ICommand, INotifier, INotification } from "../../Interfaces";

export class MacroCommand
  extends Notifier
  implements ICommand, INotifier {

  subCommands: Function[] = null;

  constructor() {
    super();
    this.subCommands = new Array<Function>();
    this.initializeMacroCommand();
  }

  initializeMacroCommand(): void {

  }

  addSubCommand(commandClassRef: Function): void {
    this.subCommands.push(commandClassRef);
  }

  execute(notification: INotification): void {
    let subCommands: Function[] = this.subCommands.slice(0);
    let len: number = this.subCommands.length;
    for (let i: number = 0; i < len; i++) {

      let commandClassRef: any = subCommands[i];
      let commandInstance: ICommand = <ICommand>new commandClassRef();
      commandInstance.initializeNotifier(this.multitonKey);
      commandInstance.execute(notification);
    }
    this.subCommands.splice(0);
  }
}